<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body,html{padding: 0;margin: 0;font-size: 14px;color:#000;}
        table {border-collapse: collapse;width: 100%;table-layout: fixed;}
        td,th {border: 1px solid #e1e1e1;padding: 0;height: 20px;line-height: 20px;text-align: center;}
        .current{color:red;}
    </style>
</head>
<body>
<table>
    <thead>
    <tr><th>一</th><th>二</th><th>三</th><th>四</th><th>五</th><th>六</th><th>日</th></tr>
    </thead>
    <tbody>
    <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>
    </tbody>
</table>
<script>
    function calendar(year, month) {
        var tody = new Date();
        var tody_moth = tody.getMonth()+1;
        var tody_year = tody.getFullYear();
        var tody_date = tody.getDate();
        console.log(tody_year+":"+tody_moth+":"+tody_date);
        var date = new Date();
        date.setFullYear(year,month-1,1);
        var lastDate = new Date();
        lastDate.setFullYear(year,month,0);
        var lastNum = lastDate.getDate();
        console.info(date);
        var tdList = document.getElementsByTagName("td");
        var day = date.getDay();
        console.log(date.getDay());
        var start = 0;
        if(day == 0){
            start = 6;
        }else{
            start = day-1;
        }
        console.log(lastNum+"day:"+day);
        for(var i = 1;i <= lastNum;i++){
            tdList[start+i-1].innerHTML = i+"";
        }
        if(tody_year == year && tody_moth == month){
           tdList[start+tody_date-1].setAttribute("class","current");
        }
    }
    calendar(2018,1);
</script>
</body>
</html>